package com.winhxd.b2c.admin.module.customer.controller;

import com.winhxd.b2c.admin.common.context.UserManager;
import com.winhxd.b2c.admin.common.security.annotation.CheckPermission;
import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.common.PagedCondition;
import com.winhxd.b2c.common.domain.customer.condition.DeliveryInfoCondition;
import com.winhxd.b2c.common.domain.customer.model.CustomerDeliveryInfo;
import com.winhxd.b2c.common.domain.system.security.enums.PermissionEnum;
import com.winhxd.b2c.common.domain.system.user.vo.UserInfo;
import com.winhxd.b2c.common.feign.customer.DeliveryInfoServiceClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lishaoping
 * @Description: 配送方式
 * @date 2019年1月7日15:07:31
 */
@Api(value = "配送方式接口", tags = "配送方式接口")
@RestController
@RequestMapping(value = "customer/deliveryInfo")
public class DeliveryInfoController {

    private Logger logger = LoggerFactory.getLogger(DeliveryInfoController.class);

    @Autowired
    private DeliveryInfoServiceClient deldiveryInfoServiceClient;

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_EDIT)
    @ApiOperation(value = "配送方式保存或修改接口", response = Integer.class, notes = "配送方式保存或修改接口")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @PostMapping(value = "/saveDeliveryInfo")
    public ResponseResult<Boolean> saveDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        UserInfo currentUser = UserManager.getCurrentUser();
        condition.setSysUserId(currentUser.getId());
        ResponseResult<Boolean> result = deldiveryInfoServiceClient.saveDeliveryInfo(condition);
        return result;
    }

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_DELETE)
    @ApiOperation(value = "配送方式删除接口", response = Integer.class, notes = "配送方式删除接口")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @PostMapping(value = "/deleteDeliveryInfo")
    public ResponseResult<Boolean> deleteDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        UserInfo currentUser = UserManager.getCurrentUser();
        condition.setSysUserId(currentUser.getId());
        ResponseResult<Boolean> result = deldiveryInfoServiceClient.deleteDeliveryInfo(condition);
        return result;
    }

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_UNUSED)
    @ApiOperation(value = "配送方式启用禁用接口", response = Integer.class, notes = "配送方式启用禁用接口")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @PostMapping(value = "/unusedDeliveryInfo")
    public ResponseResult<Boolean> unusedDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        UserInfo currentUser = UserManager.getCurrentUser();
        condition.setSysUserId(currentUser.getId());
        ResponseResult<Boolean> result = deldiveryInfoServiceClient.unusedDeliveryInfo(condition);
        return result;
    }

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_INFO)
    @ApiOperation(value = "配送方式查看接口ById", response = CustomerDeliveryInfo.class, notes = "配送方式查看接口ById")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @GetMapping(value = "/findDeliveryInfoById/{id}")
    public ResponseResult<CustomerDeliveryInfo> findDeliveryInfoById(@PathVariable("id") Long id) {
        ResponseResult<CustomerDeliveryInfo> result = deldiveryInfoServiceClient.findDeliveryInfoById(id);
        return result;
    }

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_LIST)
    @ApiOperation(value = "配送方式查看接口 对外接口不分页", response = CustomerDeliveryInfo.class, notes = "配送方式查看接口 对外接口不分页")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @PostMapping(value = "/findDeliveryInfo")
    public ResponseResult<List<CustomerDeliveryInfo>> findDeliveryInfo() {
        ResponseResult<List<CustomerDeliveryInfo>> result = deldiveryInfoServiceClient.findDeliveryInfo();
        return result;
    }

    @CheckPermission(PermissionEnum.DELIVERY_INFO_MANAGEMENT_LIST)
    @ApiOperation(value = "配送方式查看接口 对内接口 分页", response = CustomerDeliveryInfo.class, notes = "配送方式查看接口 对内接口 分页")
    @ApiResponses({@ApiResponse(code = BusinessCode.CODE_OK, message = "操作成功"), @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部错误")})
    @PostMapping(value = "/findDeliveryInfoTOPage")
    public ResponseResult<PagedList<CustomerDeliveryInfo>> findDeliveryInfoTOPage(@RequestBody PagedCondition condition) {
        ResponseResult<PagedList<CustomerDeliveryInfo>> result = deldiveryInfoServiceClient.findDeliveryInfoTOPage(condition);
        return result;
    }
}
